/**
 * 
 */
package com.net.web.controllers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.net.domain.User;
import com.net.service.UserService;
import com.net.web.form.LoginForm;

/**
 * @author Dinesh
 *
 */
public class MyFirstController extends AbstractController {
	
	final static Logger log = Logger.getLogger(MyFirstController.class);
	
	//private StudentService studentService;
	private UserService userService;

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		
		log.debug("Inside the page");
		ModelAndView mav = new ModelAndView("studenthome");
		
		LoginForm loginForm = new LoginForm();
		
		loginForm.setUserName(req.getParameter("user_name"));
		loginForm.setPassword(req.getParameter("password"));
		
		// Read the form data from HTTP request
		
		User user = userService.doSignIn(loginForm);
		
		
		if(user == null) {
			mav.setViewName("authenticationfailure");
			return mav;
		}
		
		user = userService.populateUserDetails(user);
		
		//List<Student> list = studentService.getAllStudents();
		//log.debug("The number of student records " + list.size() );
		
		
		//mav.addObject("students", list);
		mav.addObject("user", user);

		return mav;
	}

/*	*//**
	 * @return the studentService
	 *//*
	public StudentService getStudentService() {
		return studentService;
	}

	*//**
	 * @param studentService the studentService to set
	 *//*
	@Autowired
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}*/

	public UserService getUserService() {
		return userService;
	}

	@Autowired
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}
